<?php
	$action = $_GET['action'];
	switch($action) {
		case "android":
			forPhoneController::android();
			break;
		case "client_checkin":
			forPhoneController::client_checkin();
			break;
		case "getComment":
			forPhoneController::getComment();
			break;
		case "getShopStatus":
			forPhoneController::getShopStatus();
			break;
		case "getTime":
			forPhoneController::getTime();
			break;
		case "httpPostTest":
			forPhoneController::httpPostTest();
			break;
		case "listStatus":
			forPhoneController::listStatus();
			break;
		case "listTableStatus":
			forPhoneController::listTableStatus();
			break;
		case "listPhone":
			forPhoneController::listPhone();
			break;
		case "list_shop":
			forPhoneController::list_shop();
			break;
		case "setComment":
			forPhoneController::setComment();
			break;
		default:
			$_control->view('login');
			break;
	}

	class forPhoneController {
		function android() {
			require(Models_DIR.'forPhoneModel.php');
			$_model = new forPhoneModel();
			$str = forPhoneController::strCheck($_POST);
			if ($str == 0)
				forPhoneController::errorMsg('try error');
			else
				$_model->android($str["try"]);
		}
		function client_checkin() {
			require(Models_DIR.'forPhoneModel.php');
			$_model = new forPhoneModel();
			$str = forPhoneController::strCheck($_POST);
			if ($str == 0)
				forPhoneController::errorMsg('post error');
			else
				$_model->client_checkin($str);
		}
		function getComment() {
			require(Models_DIR.'forPhoneModel.php');
			$_model = new forPhoneModel();
			$str = forPhoneController::strCheck($_POST);
			if ($str == 0)
				forPhoneController::errorMsg('post error');
			else
				$_model->getComment($str);
		}
		function getShopStatus() {
			require(Models_DIR.'forPhoneModel.php');
			$_model = new forPhoneModel();
			$str = forPhoneController::strCheck($_POST);
			if ($str == 0)
				forPhoneController::errorMsg('post error');
			else
				$_model->getShopStatus($str);
		}
		function getTime() {
			require(Models_DIR.'forPhoneModel.php');
			$_model = new forPhoneModel();
			$str = forPhoneController::strCheck($_POST);
			if ($str == 0)
				forPhoneController::errorMsg('post error');
			else
				$_model->getTime($str);
		}
		function httpPostTest() {
			require(Models_DIR.'forPhoneModel.php');
			$_model = new forPhoneModel();
			$str = forPhoneController::strCheck($_POST);
			if ($str == 0)
				forPhoneController::errorMsg('post error');
			else
				$_model->httpPostTest($str);
		}
		function listStatus(){
			require(Models_DIR.'forPhoneModel.php');
			$_model = new forPhoneModel();
			$str = forPhoneController::strCheck($_POST);
			if($str == 0)
				forPhoneController::errorMsg('post error');
			else
				$_model->listStatus($str);
		}
		function listTableStatus(){
			require(Models_DIR.'forPhoneModel.php');
			$_model = new forPhoneModel();
			$str = forPhoneController::strCheck($_POST);
			if($str == 0)
				forPhoneController::errorMsg('post error');
			else
				$_model->listTableStatus($str);
		}
		function listPhone() {
			require(Models_DIR.'forPhoneModel.php');
			$_model = new forPhoneModel();
			$str = forPhoneController::strCheck($_POST);
			if ($str == 0)
				forPhoneController::errorMsg('post error');
			else
				$_model->listPhone($str);
		}
		function list_shop() {
			require(Models_DIR.'forPhoneModel.php');
			$_model = new forPhoneModel();
			$str = forPhoneController::strCheck($_POST);
			if ($str == 0)
				forPhoneController::errorMsg('post error');
			else
				$_model->list_shop($str['try']);
		}
		function setComment() {
			require(Models_DIR.'forPhoneModel.php');
			$_model = new forPhoneModel();
			$str = forPhoneController::strCheck($_POST);
			if ($str == 0)
				forPhoneController::errorMsg('post error');
			else
				$_model->setComment($str);
		}
		function strCheck($str) {
			$new_str = array();
			foreach($str as $key=>$value) {
				if (strlen($value) == 0){
					forPhoneController::errorMsg('lenth error!!');
					return 0;
				}else{
					$temp = htmlspecialchars($value);
					$new_str[$key] = $temp;
				}
			}
			return $new_str;
		}
		function errorMsg($str) {
			echo "<noscript>".$str."</noscript>";
			echo "<script language='javascript'>";
			echo "alert('".$str."');";
			echo "history.back();";
			echo "</script>";
		}
	}
?>
